#include <iostream>
#include "dymem.h"

int main(){
    using namespace std;
    DyM d1;            // 没有构造函数会调用默认的构造函数
    cout<<d1.a<<endl;
    d1.a = 10;
    d1.b = "hello";
    DyM d2(d1);       // 默认有一个copy的构造函数
    cout<<"d1 address:"<<&d1<<endl;
    cout<<"d2 address:"<<&d2<<endl;
    cout<<d2.a<<endl;     // 10
    d1.a = 20;
    cout<<d2.a<<endl;    // 10
    DyM d3 = d1;     // 类中默认存在对于=运算符的重载
    cout<<"d3 address:"<<&d3<<endl;
    cout<<"d1.b ads:"<<&d1.b<<endl;
    cout<<"d2.b ads:"<<&d2.b<<endl;
    cout<<"d3.b ads:"<<&d3.b<<endl;    // 地址均不同，说明为深拷贝，
    // 对于浅拷贝，应避免重复释放内存
    DyM* d4 = new DyM();
    DyM* d5(d4);
    DyM* d6 = d4;
    cout<<"d4 address:"<<&d4<<endl;
    cout<<"d5 address:"<<&d5<<endl;
    cout<<"d6 address:"<<&d6<<endl;
    
    return 0;
}